package model

import (
	"background/appconfig"
	"background/golden"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func Init() {
	var err error
	MysqlName := appconfig.AppName.Mysql

	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/back?charset=utf8mb4&parseTime=True&loc=Local",
		MysqlName.User,
		MysqlName.Password,
		MysqlName.Host,
		MysqlName.Port)
	golden.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
		return
	}
	fmt.Println("Mysql 连接成功")
}
